<?php
require_once( '../../includes/init.php');

function checkLogin() 
	{
		require_once ('../class_passport.php' );
		$clsPassport = new x_Passport;
		$clsPassport->appId = 10; // 通行证服务ID
		$clsPassport->encryptKey = 'k4kfEOJdi9asUWKKSDXxCKDIfjsoUH5Aa09dnAB'; // 私钥
		/****** 登陆认证 ******/
		// 第一步：
		$clsPassport->verify ();

		// 第二步，保存 Passport 信息到当前程序的 Session
		$userSession = $clsPassport->vars;
		/*
		这里为保孁 Session 代码
		*/
		if ( $clsPassport->vars['app_user_id'] > 0 )
		{
			// 若账号已&#8364;活表示已登陆当前程序
		}
		// &#59346;无需每次都验证 Passport，可以先通过用户在当前程序本身的 Session 判断是否已登陁
        //print_r($userSession);die();

		/****** 获取程序列表 ******/
		// $appType : 程序的类垁, 系统程序丁 1, 游戏丁 2
		//$appList = $clsPassport->appGetList ( $appType );
		$_SESSION['union_username'] = $userSession["username"];
		$_SESSION['union_nickname'] = $userSession["nickname"];
		return $_SESSION['union_username'];
	}
if ($_SESSION['union_username'] =='') {
    checkLogin();
}

include_once('write_cookie.php');

$smarty->cache_lifetime = 3600;
//$smarty->caching = true;
$smarty->use_sub_dirs = true;

$siteObj=alps::newClass('mod_site','mod');

$_SERVER['HTTP_HOST'] = 'kenny.9wee.com';
$siteInfo = $siteObj->getSiteInfo($_SERVER['HTTP_HOST']);                                                     //得到站点信息
if (empty($siteInfo)) die('请检查域名是否错证');
$smarty->assign('siteInfo',$siteInfo);

header("Content-type: text/html; charset=utf-8"); 
if ($siteInfo['site_status']==3) {
echo "<script>alert('网站审核没有通过');window.close();</script>";die;
}
if ($siteInfo['site_status']==1) {
echo "<script>alert('您的网站正在审核丁');window.close();</script>";die;
}

$t = explode('_', $_GET['game']);
$sid = isset($t[1])? (int)$t[1] :0;

switch($_GET['game']) {
	case 102:
		$tplpath='sanguo/';
	break;
	case 101:
		$tplpath='zuqiu1/';
	break;
	case 104:
		$tplpath='zuqiu2/';
	break;
	case 103:
		$tplpath='hero/';
	break;
	default:
		$tplpath='';
}

if ($tplpath=='') die('没有指定游戏');

$cookie_arr = $siteObj->getcookie();
$cookie=$cookie_arr['apply_id'].'_'.$_GET['game'];
if( count($t)<2 ){ $cookie.='_'.$cookie_arr['site_id']; }
$smarty->assign('cookies',$cookie);

$my_cache_id=md5($_SERVER['HTTP_HOST']);
if(!$smarty->is_cached($tplpath.'index.html',$my_cache_id.'game'.$_GET['game'])) {

	$xwgg = $siteObj->getnewslist(5,intval($_GET['game']),9);                                                                          // 新闻公告
	$smarty->assign('xwgg',$xwgg);
//print_r($xwgg);
	$yxjy = $siteObj->getnewslist(6,intval($_GET['game']),7);                                                                          // 游戏经验
	$smarty->assign('yxjy',$yxjy);

	$hdzx = $siteObj->getnewslist(7,intval($_GET['game']));                                                                          //活动中心
	$smarty->assign('hdzx',$hdzx);
 
	if( $_GET['game']==102 )
	{
		$sgactiv = $siteObj->getactivlist(intval($_GET['game']),3);
	}else{
		$sgactiv = $siteObj->getactivlist(intval($_GET['game']),4);
	}
	$smarty->assign('sgactiv',$sgactiv);
	$smarty->assign('image_domain',IMAGE_DOMAIN);
	

	$yxzn = $siteObj->getnewslist(8,intval($_GET['game']));                                                                          //游戏指南
	$smarty->assign('yxzn',$yxzn);

	$wjjl = $siteObj->getnewslist(9,intval($_GET['game']));                                                                          //玩家交流
	$smarty->assign('wjjl',$wjjl);

	$flash_pic= $siteObj->get_flashpic(intval($_GET['game']));
	$f_img='';
	$f_link='';
	$f_text='';
	foreach ($flash_pic as $key=>$fpic) {
		$link=urlencode($fpic['url_path']);
		$f_link.=$link."|";
		$f_img.=IMAGE_DOMAIN.$fpic['pic_path']."|";
		$f_text.=$fpic['title']."|";
	}
   $smarty->assign('flashlink',substr($f_link, 0, -1));
   $smarty->assign('flashimg',substr($f_img, 0, -1));
   $smarty->assign('flashtext',substr($f_text, 0, -1));

	if ($_GET['game']==104) {
		$cjwt = $siteObj->getnewslist(10,intval($_GET['game']));                                                                      //常见问题
		$smarty->assign('cjwt',$cjwt);	
	}
}
//$game=$_GET['game'];
if ($_GET['game']==101){
$smarty->assign('backaddress',urlencode($_SERVER['HTTP_HOST']));
$smarty->assign('backurl',urlencode('http://'.$_SERVER['HTTP_HOST'].'/game/?game=101'));
}
else
$smarty->assign('backaddress',$_SERVER['HTTP_HOST']);

$smarty->assign('linkurl',urlencode('show_news.php?game=104&aid=299'));

$cachepath1=substr($my_cache_id,0,2);
$cachepath2=substr($my_cache_id,2,2);
if (isset($_GET['select']) && (int)$_GET['select']==1) {
   $smarty->assign('select_js',"<script>server_select('open');</script>");
}
$smarty->display($tplpath.'index.html',$cachepath1.'|'.$cachepath2.'|'.$my_cache_id.'|'.'game'.$_GET['game']); 
?>